home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume3 / pcmail / part06 < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  58.3 KB

  1. Path: xanth!mcnc!ncsuvx!lll-winken!lll-tis!ames!necntc!ncoast!allbery
  2. From: wswietse@eutrc3.UUCP (Wietse Venema)
  3. Newsgroups: comp.sources.misc
  4. Subject: v03i007: uucp mail for pc's (6 of 8)
  5. Message-ID: <215@eutrc3.UUCP>
  6. Date: 20 Apr 88 16:53:15 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: wswietse@eutrc3.UUCP (Wietse Venema)
  9. Organization: Tech. Univ. Eindhoven, Neth.
  10. Lines: 1948
  11. Approved: allbery@ncoast.UUCP
  12.  
  13. comp.sources.misc: Volume 3, Issue 7
  14. Submitted-By: "Wietse Venema" <wswietse@eutrc3.UUCP>
  15. Archive-Name: pcmail/Part6
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 6 (of 8)."
  24. # Contents:  alias.c buildall.bat comport.h edit.c getwork.c hsearch.3
  25. #   kproto.ms mailsh.c mbox.c params.c path.c screen.h setup.c str.c
  26. #   termcap/README termcap/console.c
  27. # Wrapped by wietse@eutwc1 on Wed Apr 20 16:45:28 1988
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f alias.c -a "${1}" != "-c" ; then 
  30.   echo shar: Will not over-write existing file \"alias.c\"
  31. else
  32. echo shar: Extracting \"alias.c\" \(3315 characters\)
  33. sed "s/^X//" >alias.c <<'END_OF_alias.c'
  34. X/*++
  35. X/* NAME
  36. X/*    alias
  37. X/* SUMMARY
  38. X/*    manipulate alias data base
  39. X/* PROJECT
  40. X/*    pc-mail
  41. X/* PACKAGE
  42. X/*    mailsh
  43. X/* SYNOPSIS
  44. X/*    #include "alias.h"
  45. X/*
  46. X/*    int alias()
  47. X/* DESCRIPTION
  48. X/*    The alias data base is a text file. Each line is of the form
  49. X/*
  50. X/*        alias    replacement
  51. X/*
  52. X/*    where a replacement may consist of several words, which may
  53. X/*    be aliases themselves. Comma, blank and tab are separators.
  54. X/*    Leading or trailing blanks are ignored. If an alias is defined
  55. X/*    more than once, only the last definition will be effective.
  56. X/*
  57. X/*    alias() is invoked from the main menu and displays the contents
  58. X/*    of the alias data base. An editor is invoked if the user wants
  59. X/*    to make changes.
  60. X/* COMMANDS
  61. X/*    the program specified in the EDITOR environment variable,
  62. X/*    or a system-dependent default.
  63. X/* FILES
  64. X/*      temporary edit file in current directory
  65. X/*    alias data base file in spool directory
  66. X/* SEE ALSO
  67. X/*      pager(3), pager(5), kbdinp(3)
  68. X/* AUTHOR(S)
  69. X/*      W.Z. Venema
  70. X/*      Eindhoven University of Technology
  71. X/*      Department of Mathematics and Computer Science
  72. X/*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  73. X/* CREATION DATE
  74. X/*    Wed Apr  6 20:21:35 MET 1988
  75. X/* LAST MODIFICATION
  76. X/*    Wed Apr  6 20:21:35 MET 1988
  77. X/* VERSION/RELEASE
  78. X/*    1.0
  79. X/*--*/
  80. X
  81. X#include <errno.h>
  82. X#include "defs.h"
  83. X#include "path.h"
  84. X#include "pager.h"
  85. X#include "mailsh.h"
  86. X#include "screen.h"
  87. X#include "status.h"
  88. X
  89. X/* forward declarations */
  90. X
  91. Xhidden int edit_alias();
  92. Xhidden void junk_alias();
  93. Xhidden int show_alias();
  94. X
  95. Xhidden File *afile = 0;            /* pager file */
  96. X
  97. X/* alias - display alias data base */
  98. X
  99. Xpublic int alias()
  100. X{
  101. X    static Screen screen[] = {
  102. X    'C',    "Close",    0,    initscreen,
  103. X    'E',    "Edit",        edit_alias,"Edit alias data base",
  104. X    'P',    "Print",    print,    "Print alias data base",
  105. X    PGUP,    PgUp,        pu_pager,pageup,
  106. X    PGDN,    PgDn,        pd_pager,pagedn,
  107. X    UP,    "Up",           up_pager,csrup,
  108. X    DOWN,    "Down",         dn_pager,csrdn,
  109. X    0,    0,              show_alias,
  110. X    "(Reading alias database)",
  111. X    };
  112. X
  113. X    kbdinp(screen);                /* ask disposition */
  114. X    junk_alias();                /* forget alias display */
  115. X    return(S_REDRAW);                /* say screen was changed */
  116. X}
  117. X
  118. X/* show_alias - show alias data base or error message in middle window */
  119. X
  120. Xhidden int show_alias()
  121. X{
  122. X    static char *noalias[] = {            /* Ha ha ha ho ho hum */
  123. X    "",
  124. X    "The alias data base is empty. Normally it holds lines of the form",
  125. X    "",
  126. X    "    alias-name   one-or-more-mail-addresses",
  127. X    "",
  128. X    "You can create and change the alias data base with the E command.",
  129. X    0,
  130. X    };
  131. X    if (afile) {                /* check pager file exists */
  132. X    set_pager(afile);            /* select existing display */
  133. X    } else if (rd_pager(afile = open_pager(),aliases())) {
  134. X    mesg_pager(afile,noalias);        /* no alias database */
  135. X    }
  136. X    ds_pager();                    /* (re)draw display */
  137. X    return(0);                    /* screen is up-to-date */
  138. X}
  139. X
  140. X/* junk_alias - destroy alias data base display */
  141. X
  142. Xhidden void junk_alias()
  143. X{
  144. X    if (afile) {                /* no-op if no display */
  145. X    close_pager(afile);            /* release memory */
  146. X    afile = 0;                /* say it is gone */
  147. X    }
  148. X}
  149. X
  150. X/* edit_alias - edit or create alias data base */
  151. X
  152. Xhidden int edit_alias()
  153. X{
  154. X    register int stat;
  155. X
  156. X    if (stat = edit(aliases(),TMPALIAS))
  157. X    errdisp(stat);                /* edit() had a problem */
  158. X    junk_alias();                /* force new display */
  159. X    return(S_REDRAW);                /* say screen has changed */
  160. X}
  161. END_OF_alias.c
  162. if test 3315 -ne `wc -c <alias.c`; then
  163.     echo shar: \"alias.c\" unpacked with wrong size!
  164. fi
  165. # end of overwriting check
  166. fi
  167. if test -f buildall.bat -a "${1}" != "-c" ; then 
  168.   echo shar: Will not over-write existing file \"buildall.bat\"
  169. else
  170. echo shar: Extracting \"buildall.bat\" \(3399 characters\)
  171. sed "s/^X//" >buildall.bat <<'END_OF_buildall.bat'
  172. Xrem build file for microsoft c if you don't have a unix-compatible make tool
  173. Xrem edit this if you don't have ms-dos versions of mv and rm.
  174. X
  175. Xcl -Gs -c mailsh.c
  176. Xmv mailsh.obj mailsh.o
  177. Xcl -Gs -c call.c
  178. Xmv call.obj call.o
  179. Xcl -Gs -c email.c
  180. Xmv email.obj email.o
  181. Xcl -Gs -c file.c
  182. Xmv file.obj file.o
  183. Xcl -Gs -c screen.c
  184. Xmv screen.obj screen.o
  185. Xcl -Gs -c mbox.c
  186. Xmv mbox.obj mbox.o
  187. Xcl -Gs -c desk.c
  188. Xmv desk.obj desk.o
  189. Xrm -f shlib1.lib
  190. Xlib shlib1.lib call.o email.o file.o screen.o mbox.o desk.o ;
  191. Xcl -Gs -c kbdinp.c
  192. Xmv kbdinp.obj kbdinp.o
  193. Xcl -Gs -c pager.c
  194. Xmv pager.obj pager.o
  195. Xcl -Gs -c window.c
  196. Xmv window.obj window.o
  197. Xcl -Gs -c setup.c
  198. Xmv setup.obj setup.o
  199. Xcl -Gs -c errdisp.c
  200. Xmv errdisp.obj errdisp.o
  201. Xcl -Gs -c invoke.c
  202. Xmv invoke.obj invoke.o
  203. Xrm -f shlib2.lib
  204. Xlib shlib2.lib kbdinp.o pager.o window.o setup.o errdisp.o invoke.o ;
  205. Xcl -Gs -c makework.c
  206. Xmv makework.obj makework.o
  207. Xcl -Gs -c mailfile.c
  208. Xmv mailfile.obj mailfile.o
  209. Xcl -Gs -c deskutil.c
  210. Xmv deskutil.obj deskutil.o
  211. Xcl -Gs -c submit.c
  212. Xmv submit.obj submit.o
  213. Xcl -Gs -c edit.c
  214. Xmv edit.obj edit.o
  215. Xcl -Gs -c alias.c
  216. Xmv alias.obj alias.o
  217. Xrm -f shlib3.lib
  218. Xlib shlib3.lib makework.o mailfile.o deskutil.o submit.o edit.o alias.o ;
  219. Xcl -Gs -c dir.c
  220. Xmv dir.obj dir.o
  221. Xcl -Gs -c myalloc.c
  222. Xmv myalloc.obj myalloc.o
  223. Xcl -Gs -c params.c
  224. Xmv params.obj params.o
  225. Xcl -Gs -c path.c
  226. Xmv path.obj path.o
  227. Xcl -Gs -c newseqno.c
  228. Xmv newseqno.obj newseqno.o
  229. Xcl -Gs -c ascf.c
  230. Xmv ascf.obj ascf.o
  231. Xcl -Gs -c spoolfil.c
  232. Xmv spoolfil.obj spoolfil.o
  233. Xcl -Gs -c str.c
  234. Xmv str.obj str.o
  235. Xrm -f libgen.lib
  236. Xlib libgen dir.o myalloc.o params.o path.o newseqno.o ascf.o spoolfil.o  str.o ;
  237. Xcl -F 2000 -o mail mailsh.o -link shlib1.lib shlib2.lib shlib3.lib libgen.lib \lib\termcap
  238. Xexepack mail.exe junk
  239. Xmv junk mail.exe
  240. Xcl -Gs -c smail.c
  241. Xmv smail.obj smail.o
  242. Xcl -Gs -c unalias.c
  243. Xmv unalias.obj unalias.o
  244. Xcl -Gs -c hsearch.c
  245. Xmv hsearch.obj hsearch.o
  246. Xcl -F 2000 -o smail smail.o unalias.o hsearch.o -link libgen.lib
  247. Xexepack smail.exe junk
  248. Xmv junk smail.exe
  249. Xcl -Gs -c rmail.c
  250. Xmv rmail.obj rmail.o
  251. Xcl -F 2000 -o rmail rmail.o -link libgen.lib
  252. Xexepack rmail.exe junk
  253. Xmv junk rmail.exe
  254. Xcl -Gs -c cico.c
  255. Xmv cico.obj cico.o
  256. Xmasm comport.s ;
  257. Xmv comport.obj comport.o
  258. Xcl -Gs -c comm.c
  259. Xmv comm.obj comm.o
  260. Xcl -Gs -c connect.c
  261. Xmv connect.obj connect.o
  262. Xcl -Gs -c getwork.c
  263. Xmv getwork.obj getwork.o
  264. Xcl -Gs -c kphys.c
  265. Xmv kphys.obj kphys.o
  266. Xcl -Gs -c kpres.c
  267. Xmv kpres.obj kpres.o
  268. Xcl -Gs -c ktrans.c
  269. Xmv ktrans.obj ktrans.o
  270. Xcl -Gs -c logs.c
  271. Xmv logs.obj logs.o
  272. Xrm -f cilib1.lib
  273. Xlib cilib1 comm.o connect.o getwork.o kphys.o kpres.o ktrans.o logs.o ;
  274. Xcl -Gs -c protomsg.c
  275. Xmv protomsg.obj protomsg.o
  276. Xcl -Gs -c rmtname.c
  277. Xmv rmtname.obj rmtname.o
  278. Xcl -Gs -c scanwork.c
  279. Xmv scanwork.obj scanwork.o
  280. Xcl -Gs -c sendwork.c
  281. Xmv sendwork.obj sendwork.o
  282. Xcl -Gs -c startup.c
  283. Xmv startup.obj startup.o
  284. Xrm -f cilib2.lib
  285. Xlib cilib2 newseqno.o protomsg.o rmtname.o scanwork.o sendwork.o startup.o ;
  286. Xcl -Gs -c switcher.c
  287. Xmv switcher.obj switcher.o
  288. Xcl -Gs -c xpres.c
  289. Xmv xpres.obj xpres.o
  290. Xcl -Gs -c gpres.c
  291. Xmv gpres.obj gpres.o
  292. Xcl -Gs -c gtrans.c
  293. Xmv gtrans.obj gtrans.o
  294. Xcl -Gs -c gphys.c
  295. Xmv gphys.obj gphys.o
  296. Xrm -f cilib3.lib
  297. Xlib cilib3 switcher.o xpres.o gpres.o gtrans.o gphys.o ;
  298. Xcl -F 2000 -o junk cico.o comport.o -link cilib1.lib cilib2.lib cilib3.lib libgen
  299. Xexepack junk.exe cico.exe 
  300. Xrm -f junk.exe
  301. Xcl -Gs -c cmail.c
  302. Xmv cmail.obj cmail.o
  303. Xcl -F 2000 -o cmail cmail.o invoke.o -link libgen.lib
  304. Xexepack cmail.exe junk
  305. Xmv junk cmail.exe
  306. END_OF_buildall.bat
  307. if test 3399 -ne `wc -c <buildall.bat`; then
  308.     echo shar: \"buildall.bat\" unpacked with wrong size!
  309. fi
  310. # end of overwriting check
  311. fi
  312. if test -f comport.h -a "${1}" != "-c" ; then 
  313.   echo shar: Will not over-write existing file \"comport.h\"
  314. else
  315. echo shar: Extracting \"comport.h\" \(3203 characters\)
  316. sed "s/^X//" >comport.h <<'END_OF_comport.h'
  317. X/*
  318. X * Comport.h
  319. X *
  320. X * defines the bit masking for the get_mcr()
  321. X *
  322. X * @(#) comport.h    Version hoptoad-1.3    87/03/24
  323. X *
  324. X * Copyright (C) Tim M. Pozar 1987
  325. X * Anyone can use this code for anything, but it is copyright by Tim
  326. X * and you must leave his copyright in the code.
  327. X *
  328. X */
  329. X
  330. X/*
  331. X * get_msr()
  332. X *   Function to read (get) the byte located in the Modem Status 
  333. X * Register (3FEh).  The table below describes the byte returned.
  334. X *   bit  description
  335. X *    0   Delta Clear to Send (DCTS)
  336. X *        Indicates that the !CTS input to the chip has changed state
  337. X *        since the last time it was read by the processor.
  338. X *    1   Delta Data Set Ready (DDSR)
  339. X *        Indicates that the !DRS input to the chip has changed since 
  340. X *        last time it was read by the processor.
  341. X *    2   Trailing Edge Ring Indicator (TERI)
  342. X *        Indicates that the !RI input to the chip has changed from
  343. X *        an on (logical 1) to an off (logical 0) condition.
  344. X *    3   Delta Rx Line Signal detect (DRLSD)
  345. X *        Indicates that the !RLSD input to the chip has changed state.
  346. X * NOTE: Whenever bit 0, 1, 2, or 3 is set to a logical 1, a modem status
  347. X *       interrupt is generated.
  348. X *
  349. X *    4   Clear to Send (CTS)
  350. X *        This bit is the complement of the clear to send (!CTS) input.
  351. X *        If bit 4 (LOOP) of the MCR is set to a logical 1, this is 
  352. X *        equivalent to RTS in the MCR.
  353. X *    5   Data Set Ready (DSR)
  354. X *        This bit is the complement of the data set ready (!DSR) input.
  355. X *        If bit 4 (LOOP) of the MCR is set to a logical 1, this is 
  356. X *        equivalent to DTR in the MCR.
  357. X *    6   Ring Indicator (RI)
  358. X *        This bit is the complement of the ring indicator (!RI) input.
  359. X *        If bit 4 (LOOP) of the MCR is set to a logical 1, this is 
  360. X *        equivalent to OUT 1 in the MCR.
  361. X *    7   Receive Line Signal Detect (RLSD) or Carrier Detect (CD).
  362. X *        This bit is the complement of the received line signal detect
  363. X *        (!RLSD) input. If bit 4 (LOOP) of the MCR is set to a logical 1,
  364. X *        this is equivalent to OUT 2 in the MCR.
  365. X */
  366. X
  367. X#define  DCTS       1
  368. X#define  DDSR       2
  369. X#define  TERI       4
  370. X#define  DRLSD      8
  371. X#define  CTS       16
  372. X#define  DST       32
  373. X#define  RI        64
  374. X#define  RLSD     128   /* Also known as ... */
  375. X#define  CD       128   
  376. X#define  set_tty        SET_TTY     /* find current settings, and initialize */
  377. X#define  reset_tty      RESET_TTY   /* reset to settings that set_tty() found */
  378. X#define  get_msr        GET_MSR     /* get MSR byte from port. */
  379. X#define  init_comm      INIT_COMM   /* initialize the comm port interupts, */
  380. X#define  uninit_comm    UNINIT_COMM /* remove initialization, */
  381. X#define  set_xoff       SET_XOFF    /* enable/disable XON/XOFF, */
  382. X#define  get_xoff       GET_XOFF    /* read XON/XOFF state, */
  383. X#define  rcvd_xoff      RCVD_XOFF   /* returns true if XOFF rcvd, */
  384. X#define  sent_xoff      SENT_XOFF   /* true if XOFF sent, */
  385. X#define  inp_cnt        INP_CNT     /* returns count of rcv chars, */
  386. X#define  inp_char       INP_CHAR    /* get one char from buffer, */
  387. X#define  inp_flush      INP_FLUSH   /* flush input buffer, */
  388. X#define  outp_char      OUTP_CHAR   /* output a character, */
  389. END_OF_comport.h
  390. if test 3203 -ne `wc -c <comport.h`; then
  391.     echo shar: \"comport.h\" unpacked with wrong size!
  392. fi
  393. # end of overwriting check
  394. fi
  395. if test -f edit.c -a "${1}" != "-c" ; then 
  396.   echo shar: Will not over-write existing file \"edit.c\"
  397. else
  398. echo shar: Extracting \"edit.c\" \(3259 characters\)
  399. sed "s/^X//" >edit.c <<'END_OF_edit.c'
  400. X/*++
  401. X/* NAME
  402. X/*    edit 3
  403. X/* SUMMARY
  404. X/*    edit a file
  405. X/* PROJECT
  406. X/*    pc-mail
  407. X/* PACKAGE
  408. X/*    mailsh
  409. X/* SYNOPSIS
  410. X/*    #include "edit.h"
  411. X/*
  412. X/*    int edit(fname,tname)
  413. X/*    char *fname,*tname;
  414. X/* DESCRIPTION
  415. X/*    edit() copies the file in fname to the file tname,
  416. X/*    invokes the editor, and copies the result back.
  417. X/* COMMANDS
  418. X/*    the program specified in the EDITOR environment variable,
  419. X/*    or a system-dependent default.
  420. X/* AUTHOR(S)
  421. X/*      W.Z. Venema
  422. X/*      Eindhoven University of Technology
  423. X/*      Department of Mathematics and Computer Science
  424. X/*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  425. X/* CREATION DATE
  426. X/*    Wed Apr  6 20:21:35 MET 1988
  427. X/* LAST MODIFICATION
  428. X/*    Wed Apr  6 20:21:35 MET 1988
  429. X/* VERSION/RELEASE
  430. X/*    1.0
  431. X/*--*/
  432. X
  433. X#include <errno.h>
  434. X#include "defs.h"
  435. X#include "path.h"
  436. X#include "mailsh.h"
  437. X#include "status.h"
  438. X
  439. X#ifdef MSDOS
  440. X#   include <fcntl.h>
  441. X#endif
  442. X
  443. X/* edit - edit or create a file */
  444. X
  445. X/*
  446. X* Some editors (wordstar) do not accept path names. grrrr. 
  447. X* So we copy the edit file to a temp file in the current directory.
  448. X* After editing, the temp file is copied back. We do not move files, 
  449. X* since current dir and the spool dir may be in different file systems, 
  450. X* and people might turn off the machine and lose their edites.
  451. X*/
  452. X
  453. Xpublic int edit(fname,tname)
  454. Xchar *fname,*tname;
  455. X{
  456. X    register int stat = 0;
  457. X    register FILE *fp;
  458. X
  459. X    /*
  460. X    * First make sure that we can get write permission on the permanent file
  461. X    * and temporary file (if they exist). 
  462. X    * Create an empty temp file if we are not editing an existing file.
  463. X    */
  464. X
  465. X    if (chmod(fname,0666) && errno != ENOENT) {
  466. X    stat = E_WRITERR;            /* original file is protected */
  467. X    } else if (chmod(tname,0666) && errno != ENOENT) {
  468. X    stat = E_WRITERR;            /* scratch file is protected */
  469. X    } else if ((fp = fopen(fname,"a")) == 0) {
  470. X    stat = E_WRITERR;            /* file system is protected? */
  471. X    } else if (fclose(fp),stat = cpfile(fname,tname)) {
  472. X    /* void */;                /* could not make edit copy */
  473. X    } else {
  474. X    patience();                /* this may take some time */
  475. X    kbdrest();                /* reset tty modes */
  476. X    if (stat = invokelp(editor,tname,(char *) 0))/* call editor */
  477. X        stat = (stat == E_NOPROG ? stat : E_UNKNOWN);
  478. X    else
  479. X        stat = cpfile(tname,fname);        /* copy back */
  480. X    kbdinit();                /* set tty modes */
  481. X    unlink(tname);                /* don't check status */
  482. X    }
  483. X    chmod(fname,0444);                /* protect destination file */
  484. X    return(stat);
  485. X}
  486. X
  487. X/* cpfile - yet another file copy function */
  488. X
  489. Xhidden int cpfile(from,to)
  490. Xchar *from,*to;
  491. X{
  492. X    register FILE *in,*out;            /* file pointers */
  493. X    int stat = 0;                /* error status */
  494. X
  495. X    if ((in = fopen(from,"r")) == 0) {        /* cannot read source */
  496. X    return(E_READERR);
  497. X    } else if ((out = fopen(to,"w")) == 0) {    /* cannot write destination */
  498. X    fclose(in);
  499. X    return(E_WRITERR);
  500. X    } else {
  501. X    register int c;                /* character buffer */
  502. X#ifdef O_BINARY
  503. X    setmode(fileno(in),O_BINARY);        /* get rid of the */
  504. X    setmode(fileno(out),O_BINARY);        /* crlf translation */
  505. X#endif
  506. X    while ((c = getc(in)) != EOF)
  507. X       putc(c,out);
  508. X    if (ferror(in))                /* check read error status */
  509. X        stat = E_READERR;
  510. X    else if (ferror(out))            /* check write error status */
  511. X        stat = E_WRITERR;
  512. X    fclose(in);
  513. X    fclose(out);
  514. X    return(stat);                /* at most one type of error */
  515. X    }
  516. X}
  517. END_OF_edit.c
  518. if test 3259 -ne `wc -c <edit.c`; then
  519.     echo shar: \"edit.c\" unpacked with wrong size!
  520. fi
  521. # end of overwriting check
  522. fi
  523. if test -f getwork.c -a "${1}" != "-c" ; then 
  524.   echo shar: Will not over-write existing file \"getwork.c\"
  525. else
  526. echo shar: Extracting \"getwork.c\" \(2772 characters\)
  527. sed "s/^X//" >getwork.c <<'END_OF_getwork.c'
  528. X/*++
  529. X/* NAME
  530. X/*    getwork 3
  531. X/* SUMMARY
  532. X/*    receive work from remote system
  533. X/* PROJECT
  534. X/*    pc-mail
  535. X/* PACKAGE
  536. X/*    cico
  537. X/* SYNOPSIS
  538. X/*    #include "work.h"
  539. X/*
  540. X/*      work *rmtwork(rqst)
  541. X/*      char *rqst;
  542. X/*
  543. X/*    void getwork(wrk)
  544. X/*    work *wrk;
  545. X/* DESCRIPTION
  546. X/*      rmtwork() parses a remote Send request. A suitable destination
  547. X/*    file is opened. The resulting work structure is for use by 
  548. X/*    getwork().
  549. X/*
  550. X/*    getwork() receives a file from the remote system, after the
  551. X/*    necessary preparations have been done by rmtwork().
  552. X/*    The file is deleted in case of transmission failure.
  553. X/* FUNCTIONS AND MACROS
  554. X/*    trap(), locname()
  555. X/* SEE ALSO
  556. X/*    sendwork(), scanwork()
  557. X/* DIAGNOSTICS
  558. X/*    Exceptions are handled with longjmp(systrap,errorcode).
  559. X/*
  560. X/*    rmtwork() traps in case of invalid requests or if the destination
  561. X/*    file could not be opened.
  562. X/*
  563. X/*    getwork() traps in case of read/write errors.
  564. X/* AUTHOR(S)
  565. X/*    W.Z. Venema
  566. X/*    Eindhoven University of Technology
  567. X/*    Department of Mathematics and Computer Science
  568. X/*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  569. X/* CREATION DATE
  570. X/*    Sat Mar 28 16:57:57 GMT+1:00 1987
  571. X/* LAST MODIFICATION
  572. X/*    Mon Apr  4 23:40:43 MET 1988
  573. X/* VERSION/RELEASE
  574. X/*    1.3
  575. X/*--*/
  576. X
  577. X#include "defs.h"
  578. X#include "logs.h"
  579. X#include "status.h"
  580. X#include "work.h"
  581. X#include "params.h"
  582. X#include "comm.h"
  583. X
  584. X/* rmtwork - parse remote S request and open destination file */
  585. X
  586. Xpublic work *rmtwork(rqst)
  587. Xchar *rqst;
  588. X{
  589. X    static work wrk;
  590. X    char path[BUFSIZ];
  591. X
  592. X    if (sscanf(rqst,"S %*s %s",path) != 1)    /* pick destination file name */
  593. X    trap(E_LOST,"BAD REQUEST FORMAT");
  594. X    debug(5)("rmtwork: path %s\n",path);
  595. X    strcpy(wrk.path,locname(path));        /* convert to local name */
  596. X    debug(5)("rmtwork: file %s\n",wrk.path);
  597. X    if ((wrk.fp = fopen(wrk.path,"w")) == 0)    /* try to open that file */
  598. X    trap(E_WRITERR,"CAN'T CREATE FILE (%s)",sys_errlist[errno]);
  599. X    return(&wrk);
  600. X}
  601. X
  602. X/* getwork - receive file from remote host */
  603. X
  604. Xpublic void getwork(wrk)
  605. Xregister work *wrk;
  606. X{
  607. X    char buf[BUFSIZ];
  608. X    register int nread;
  609. X    register int werror;
  610. X
  611. X    while ((nread = CALL(Read)(ttfd,buf,BUFSIZ)) > 0 &&
  612. X    fwrite(buf,sizeof(*buf),nread,wrk->fp) == nread)
  613. X    /* void */ ;
  614. X    werror = ferror(wrk->fp);            /* record error status */
  615. X    fclose(wrk->fp);
  616. X
  617. X    if (nread < 0) {                /* did the protocol fail? */
  618. X    chmod(wrk->path,0666);            /* make file deletable */
  619. X    unlink(wrk->path);            /* remove file */
  620. X    trap(E_LOST,"FAILED (lost link)");    /* handle exception */
  621. X    /* NOTREACHED */
  622. X    } else if (werror) {            /* file write error? */
  623. X    chmod(wrk->path,0666);            /* make file deletable */
  624. X    unlink(wrk->path);            /* remove file */
  625. X    trap(E_WRITERR,"FILE WRITE ERROR (%s)",sys_errlist[errno]);
  626. X    /* NOTREACHED */
  627. X    } else {
  628. X    chmod(wrk->path,0444);            /* protect the file */
  629. X    }
  630. X}
  631. END_OF_getwork.c
  632. if test 2772 -ne `wc -c <getwork.c`; then
  633.     echo shar: \"getwork.c\" unpacked with wrong size!
  634. fi
  635. # end of overwriting check
  636. fi
  637. if test -f hsearch.3 -a "${1}" != "-c" ; then 
  638.   echo shar: Will not over-write existing file \"hsearch.3\"
  639. else
  640. echo shar: Extracting \"hsearch.3\" \(3042 characters\)
  641. sed "s/^X//" >hsearch.3 <<'END_OF_hsearch.3'
  642. X.TH HSEARCH 3c local
  643. X.SH NAME
  644. Xhsearch, hcreate, hdestroy \- manage hash search tables
  645. X.SH SYNOPSIS
  646. X.nf
  647. X.ft B
  648. Xtypedef struct entry {
  649. X    char *key;
  650. X    char *data;
  651. X    } ENTRY;
  652. X
  653. Xtypedef enum {
  654. X    FIND,
  655. X    ENTER
  656. X    } ACTION;
  657. X
  658. XENTRY *hsearch (item, action)
  659. XENTRY item;
  660. XACTION action;
  661. X
  662. Xint hcreate (nel)
  663. Xunsigned int nel;
  664. X
  665. Xvoid hdestroy ();
  666. X.br
  667. X.ft R
  668. X.fi
  669. X.SH DESCRIPTION
  670. X.I Hsearch
  671. Xis a simple, public domain, reimplementation of the routine of the same
  672. Xname in
  673. X.SM UNIX
  674. XSystem V.
  675. X.PP
  676. X.I Hsearch
  677. Xreturns a pointer into a hash table where a given element can be found.
  678. XAn
  679. X.I item
  680. Xto be stored in the table is of type ENTRY.
  681. X.I Item.key
  682. Xpoints to the key used for comparison, while
  683. X.I item.data
  684. Xpoints to the data to be associated with the key.
  685. XIf the data pointed to is not a character string, it should be cast
  686. Xto type pointer-to-character before being assigned.
  687. XNote that
  688. X.I item
  689. Xis a structure, and
  690. X.I not
  691. Xa pointer to a structure.
  692. XIf the value of
  693. X.I action
  694. Xis FIND,
  695. X.I hsearch
  696. Xwill return a pointer to the item in the table, if it is there, otherwise
  697. Xit will return NULL.  If the action is ENTER, it will return a pointer
  698. Xto the new item, or NULL if it could not add the item to the table.
  699. XNote that if the action is ENTER, and the item was already in the table, the
  700. X.I data
  701. Xfield will be updated from the new
  702. X.IR item .
  703. X.PP
  704. X.I Hsearch
  705. Xdoes not provide all the (compile-time) options of the original routine;
  706. Xinstead it uses a
  707. X.I remainder modulo table size
  708. Xhashing algorithm,
  709. X.I chaining
  710. X(linked lists) to resolve collisions, with new entries being placed at
  711. Xthe end, and
  712. X.IR strcmp (3)
  713. Xfor the comparison function.
  714. XIt was felt that a simple reimplementation was called for,
  715. Xinstead of a brand new hash table package,
  716. Xsince the interface provided is a clean one,
  717. Xbut the original source code is not publicly available.
  718. X.PP
  719. X.I Hcreate
  720. Xcreates the hash table, allocating enough space for it.  It must be
  721. Xcalled before
  722. X.IR hsearch .
  723. X.I Nel
  724. Xis an estimate of the number of hash buckets that will be needed;
  725. Xthe table size will be adjusted up to the next largest prime number.  If
  726. X.I nel
  727. Xis larger than the largest prime known to
  728. X.IR hcreate , " nel"
  729. Xwill be used directly.
  730. X.PP
  731. X.I Hdestroy
  732. Xdestroys the hash table, freeing up all its storage.  It may be followed
  733. Xby another call to
  734. X.IR hcreate .
  735. X.SH SEE ALSO
  736. X.IR malloc (3),
  737. X.IR strcmp (3),
  738. Xthe various other searching routines available with System V.
  739. X.SH DIAGNOSTICS
  740. X.I Hsearch
  741. Xreturns NULL
  742. Xif either the action was FIND and the item is not in the table, or
  743. Xthe action was ENTER but the item could not be inserted.
  744. X.PP
  745. X.I Hcreate
  746. Xreturns zero if it could not create the initial table; it returns
  747. Xone if all went well.
  748. X.SH BUGS
  749. X.PP
  750. XOnly one hash table may be active at a given time.
  751. X.PP
  752. XNot as flexible as the original System V implementation.
  753. X.SH AUTHOR
  754. X.nf
  755. XArnold Robbins
  756. XSchool of Information and Computer Science
  757. XGeorgia Institute of Technology
  758. XAtlanta, Georgia   30332
  759. X
  760. XCSNET:    arnold@gatech
  761. XARPA:    arnold%gatech.csnet@csnet-relay.arpa
  762. XUUCP:    { akgua, allegra, hplabs, ihnp4, seismo, ut-sally }!gatech!arnold
  763. END_OF_hsearch.3
  764. if test 3042 -ne `wc -c <hsearch.3`; then
  765.     echo shar: \"hsearch.3\" unpacked with wrong size!
  766. fi
  767. # end of overwriting check
  768. fi
  769. if test -f kproto.ms -a "${1}" != "-c" ; then 
  770.   echo shar: Will not over-write existing file \"kproto.ms\"
  771. else
  772. echo shar: Extracting \"kproto.ms\" \(2984 characters\)
  773. sed "s/^X//" >kproto.ms <<'END_OF_kproto.ms'
  774. X.TL
  775. Xuucp k protocol description
  776. X.AU
  777. XW.Z. Venema
  778. XEindhoven University of Technology
  779. X.AE
  780. X.NH
  781. XIntroduction
  782. X.LP
  783. XThe k protocol has been developed for the Sytek Localnet local area
  784. Xnetwork at the Eindhoven University of Technology (TUE).
  785. XMain features of this network are:
  786. X.IP     1
  787. XNetwork partners may talk at different baudrates. This implies that the network
  788. Xdoes some buffering. This may cause timing
  789. Xproblems (e.g. a system sending at 9600 baud to a system reading at 1200 baud).
  790. X.IP     2
  791. XThe network needs a flow control mechanism. Usually this is
  792. Xbased on the XON/XOFF protocol. Other control character sequences are used
  793. Xfor commands to the network.
  794. X.IP     3
  795. XSome network stations are connected to telephone modems.
  796. X.LP
  797. XFor these reasons, the k protocol must (i) cope with on XON/XOFF flow
  798. Xcontrol, (ii) be suitable for 7-bit data paths, (iii) avoid
  799. Xcontrol characters and (iv) provide reliable operation
  800. Xover telephone lines as well as over the local area network.
  801. X.NH
  802. XPackets
  803. X.LP
  804. XData are sent as checksummed 256-byte packets, terminated by an
  805. XASCII CR. Except for the packet header (^P), the k protocol only uses
  806. XASCII codes 040 through 0137. Three data bytes are expanded to four
  807. Xbytes upon transmission. Theoretically, this reduces throughput by 25 percent.
  808. XAt 1200 baud, actual performances are:
  809. X.DS
  810. Xuucp, g protocol    110 cps
  811. Xuucp, k protocol    74 cps
  812. Xc-kermit        67 cps
  813. X.DE
  814. XNote that the values for c-kermit are for text files, with repeat-count
  815. Xcompression enabled.
  816. X.PP
  817. XThe packet types are a subset of those used in the kermit programs:
  818. X.DS
  819. XD packets contain data.
  820. XY packets are sent when a correct data packet was received.
  821. XN packets are sent when incorrect data was received.
  822. XA packets are sent to shut down the k protocol.
  823. X.DE
  824. XA packet always begins with a header:
  825. X.DS
  826. XSOH     packet header, ASCII control-P
  827. Xlen     (size of data, low 6 bits) + 32
  828. Xlen     (size of data, high 6 bits) + 32
  829. Xnum     (packet number mod 64) + 32
  830. Xtype    packet type
  831. Xcheck   one-byte type-1 kermit checksum
  832. X.DE
  833. X.LP
  834. XThe header is followed by checksummed data if len > 0:
  835. X.DS
  836. Xdata    len data bytes
  837. Xcheck1  (upper 2 bits of type-3 kermit 16-bit checksum) + 32
  838. Xcheck2  (middle 6 bits of type-3 kermit 16-bit checksum) + 32
  839. Xcheck3  (lower 6 bits of type-3 kermit 16-bit checksum) + 32
  840. X.DE
  841. X.LP
  842. XEvery packet is followed by an ASCII carriage return, which is
  843. Xignored upon reception of a packet. It prevents timeout errors
  844. Xwhen one byte gets lost (the most common case).
  845. X.NH
  846. XHandshake
  847. X.LP
  848. XHandshake is on a per-packet basis; a transmitter will not send
  849. Xanother data packet before it knows that the receiver got the data
  850. Xin good condition. There are various ways to obtain that knowledge:
  851. Xthe receiver may send an ACK message (usual case), or a NAK for
  852. Xthe next data packet, or a data packet with the next sequence number.
  853. X.PP
  854. XThe protocol is aborted when an unexpected
  855. Xpacket type or when a packet out of sequence is received.
  856. XSince 'A' packets are never expected, they always cause a protocol
  857. Xfault.
  858. END_OF_kproto.ms
  859. if test 2984 -ne `wc -c <kproto.ms`; then
  860.     echo shar: \"kproto.ms\" unpacked with wrong size!
  861. fi
  862. # end of overwriting check
  863. fi
  864. if test -f mailsh.c -a "${1}" != "-c" ; then 
  865.   echo shar: Will not over-write existing file \"mailsh.c\"
  866. else
  867. echo shar: Extracting \"mailsh.c\" \(3963 characters\)
  868. sed "s/^X//" >mailsh.c <<'END_OF_mailsh.c'
  869. X/*++
  870. X/* NAME
  871. X/*      mailsh
  872. X/* SUMMARY
  873. X/*      visual mail-shell
  874. X/* PROJECT
  875. X/*      pc-mail
  876. X/* PACKAGE
  877. X/*      mail
  878. X/* SYNOPSIS
  879. X/*      mail
  880. X/* DESCRIPTION
  881. X/*      mail is an interactive program for reading, receiving
  882. X/*      and producing electronic mail. Actually, most of the work
  883. X/*    is done by programs called by the mail program.
  884. X/*
  885. X/*      By default, the program presents the user display of a list of
  886. X/*      mail messages in the form of one-line summaries. Single-key 
  887. X/*    commands are available to select and manipulate mail messages.
  888. X/*    Mail messages are created with an editor chosen by the user.
  889. X/*
  890. X/*      The name of the spool directory, printer program and editor
  891. X/*      are taken from the environment, or assume system-dependent defaults.
  892. X/* ENVIRONMENT
  893. X/*      MAILDIR        name of spool directory
  894. X/*      EDITOR          name of program to create mail
  895. X/*    MAILPRN        name of program/file to print with/to
  896. X/*    MAILCMD        command to execute upon termination
  897. X/* COMMANDS
  898. X/*      cico            network communications program
  899. X/*      rmail           postprocessor for mail received by cico
  900. X/* FILES
  901. X/*      The mail system maintains various files in a spool directory,
  902. X/*      as well as a logfile of all network transactions.
  903. X/* SEE ALSO
  904. X/*      path(3)         system-dependent path names
  905. X/* DIAGNOSTICS
  906. X/*      Error messages should be self-explanatory.
  907. X/* BUGS
  908. X/*      The user has to explicitly tell the system to contact a remote
  909. X/*    mail host. This is a limitation of MS-DOS, not of the program.
  910. X/* AUTHOR(S)
  911. X/*      W.Z. Venema
  912. X/*      Eindhoven University of Technology
  913. X/*      Department of Mathematics and Computer Science
  914. X/*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  915. X/* CREATION DATE
  916. X/*      Thu Apr  2 21:54:08 GMT+1:00 1987
  917. X/* LAST MODIFICATION
  918. X/*    Mon Apr  4 23:44:44 MET 1988
  919. X/* VERSION/RELEASE
  920. X/*    1.3
  921. X/*--*/
  922. X
  923. X#include <signal.h>
  924. X#include "defs.h"
  925. X#include "path.h"
  926. X#include "status.h"
  927. X#include "mailsh.h"
  928. X#include "window.h"
  929. X
  930. X/* forward declarations */
  931. X
  932. Xhidden int checkfiles();
  933. X
  934. X/* for now, don't even try to look at command args */
  935. X
  936. Xpublic main(argc,argv)
  937. Xint argc;
  938. Xchar **argv;
  939. X{
  940. X    register int stat;
  941. X
  942. X    /* 
  943. X    * Initializations: get screen control and function-key codes (wininit).
  944. X    * check if the limit on the number of open files is ok (checkfiles),
  945. X    * get the values from environment variables (pathinit), set the
  946. X    * terminal driver to the desired mode (kbdinit), check for partally
  947. X    * processed new mail with the rmail program.
  948. X    * Also make sure that our file permissions are safe (umask).
  949. X    */
  950. X
  951. X    if (!isatty(fileno(stdin))) {
  952. X    perror("mail: standard input");
  953. X    exit(1);
  954. X    }
  955. X
  956. X    umask(022);                /* avoid problems */
  957. X    wininit();                          /* do termcap stuff */
  958. X    clrscreen();                         /* clear screen */
  959. X    (stat = checkfiles())        /* get max nbr of open files */
  960. X    || (stat = pathinit())        /* get spool, printer, editor */
  961. X    || (stat = invokelp(RMAIL,(char *)0));/* just in case there's mail */
  962. X    kbdinit();                          /* set to tty RAW, NOECHO */
  963. X    if (stat)
  964. X    errdisp(stat);            /* we have a problem */
  965. X
  966. X    /* enter the main command loop */
  967. X
  968. X    desk();                /* start the machine */
  969. X
  970. X    /* finalizations */
  971. X
  972. X    kbdrest();                          /* restore tty driver */
  973. X    clrscreen();                         /* clear screen */
  974. X    fflush(stdout);
  975. X    onexit(mailcmd);            /* do exit command */
  976. X    exit(0);                            /* huh?? */
  977. X    /* NOTREACHED */
  978. X}
  979. X
  980. X/* checkfiles - make sure we can open as many files as we want */
  981. X
  982. Xhidden int checkfiles()
  983. X{
  984. X    register int i;
  985. X    int fds[MINFILES];
  986. X    register int stat;
  987. X
  988. X    for (i = 0; i < MINFILES; i++)              /* try to open many files */
  989. X    if ((fds[i] = open(NULLDEV,0)) < 0)
  990. X        break;
  991. X
  992. X    stat = (i < MINFILES ? E_FILENO : 0);    /* did we fail? */
  993. X
  994. X    while (--i >= 0)                            /* release files */
  995. X    close(fds[i]);
  996. X    return(stat);
  997. X}
  998. END_OF_mailsh.c
  999. if test 3963 -ne `wc -c <mailsh.c`; then
  1000.     echo shar: \"mailsh.c\" unpacked with wrong size!
  1001. fi
  1002. # end of overwriting check
  1003. fi
  1004. if test -f mbox.c -a "${1}" != "-c" ; then 
  1005.   echo shar: Will not over-write existing file \"mbox.c\"
  1006. else
  1007. echo shar: Extracting \"mbox.c\" \(2946 characters\)
  1008. sed "s/^X//" >mbox.c <<'END_OF_mbox.c'
  1009. X/*++
  1010. X/* NAME
  1011. X/*      mbox 3
  1012. X/* SUMMARY
  1013. X/*      display incoming/outgoing mail messages
  1014. X/* PROJECT
  1015. X/*      pc-mail
  1016. X/* PACKAGE
  1017. X/*      mailsh
  1018. X/* SYNOPSIS
  1019. X/*    #include "pager.h"
  1020. X/*    #include "mbox.h"
  1021. X/*
  1022. X/*      int mbox(type,msgid)
  1023. X/*    char *type;
  1024. X/*    int msgid;
  1025. X/* DESCRIPTION
  1026. X/*      mbox() is invoked when the user has selected an incoming or
  1027. X/*    outgoing mail message (not a message in preparation)
  1028. X/*    from the main mail box menu. It instructs the pager to display 
  1029. X/*    the selected mail message. The message type parameter is 
  1030. X/*    a string with the type of message
  1031. X/*    (see screen.h), msgid is the numerical message id. If the file is
  1032. X/*    read for the first time (type == "New"), it will be marked as read.
  1033. X/*
  1034. X/*      The user has the usual options for manipulating the message
  1035. X/*    being displayed.
  1036. X/* FILES
  1037. X/*      mail header files in the spool directory
  1038. X/* SEE ALSO
  1039. X/*      pager(3), pager(5), kbdinp(3)
  1040. X/* DIAGNOSTICS
  1041. X/*      If a selected mail message could not be found an error message
  1042. X/*      is displayed instead.
  1043. X/* AUTHOR(S)
  1044. X/*      W.Z. Venema
  1045. X/*      Eindhoven University of Technology
  1046. X/*      Department of Mathematics and Computer Science
  1047. X/*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  1048. X/* CREATION DATE
  1049. X/*      Sun Apr  5 13:01:12 GMT+1:00 1987
  1050. X/* LAST MODIFICATION
  1051. X/*    Mon Apr  4 23:45:14 MET 1988
  1052. X/* VERSION/RELEASE
  1053. X/*    1.3
  1054. X/*--*/
  1055. X
  1056. X#include "defs.h"
  1057. X#include "path.h"
  1058. X#include "pager.h"
  1059. X#include "screen.h"
  1060. X#include "mailsh.h"
  1061. X
  1062. Xhidden File *letter = 0;            /* pager file */
  1063. X
  1064. X/* show_letter - display selected mail message */
  1065. X
  1066. Xhidden int show_letter()
  1067. X{
  1068. X    set_pager(letter);                /* select message display */
  1069. X    ds_pager();                    /* put it on the screen */
  1070. X    return(0);                    /* say screen is ok */
  1071. X}
  1072. X
  1073. X/* mbox - user has selected a non-work mail message file */
  1074. X
  1075. Xpublic int mbox(type,id)
  1076. Xchar *type;
  1077. Xint id;
  1078. X{
  1079. X    static Screen screen[] = {
  1080. X    'C',    "Close",        0,      initscreen,
  1081. X    'D',    "Delete",       delete,    delcurr,
  1082. X    'M',    "Mail",        mailfile,"Mail a copy of this message",
  1083. X    'P',    "Print",        print,    printcurr,
  1084. X    'S',    "Save",         save,    "Save this message to ordinary file",
  1085. X    'W',    "Work",        makework,"Save this message to work file",
  1086. X    PGUP,    PgUp,        pu_pager,pageup,
  1087. X    PGDN,    PgDn,        pd_pager,pagedn,
  1088. X    UP,    "Up",           up_pager,csrup,
  1089. X    DOWN,    "Down",         dn_pager,csrdn,
  1090. X    0,    0,              show_letter,"(Reading a mail message)",
  1091. X    };
  1092. X    register char *seen;
  1093. X
  1094. X    if (rd_pager(letter = open_pager(),message)) {
  1095. X    mesg_pager(letter,m_msgread);        /* no file or read error */
  1096. X    } else if (strcmp(type,"New")) {        /* !!ANONYMOUS CONSTANT!! */
  1097. X    /* void */ ;                /* not a new message */
  1098. X    } else if (rename(comment,seen = in_meta(id)) == 0) {
  1099. X    strcpy(comment,seen);            /* mark message as read */
  1100. X    junk_desk();                /* say desk-top outdated */
  1101. X    }
  1102. X    kbdinp(screen);                /* look at the screen */
  1103. X    close_pager(letter),letter = 0;        /* destroy the display */
  1104. X    return(S_REDRAW);                /* force screen redrawing */
  1105. X}
  1106. END_OF_mbox.c
  1107. if test 2946 -ne `wc -c <mbox.c`; then
  1108.     echo shar: \"mbox.c\" unpacked with wrong size!
  1109. fi
  1110. # end of overwriting check
  1111. fi
  1112. if test -f params.c -a "${1}" != "-c" ; then 
  1113.   echo shar: Will not over-write existing file \"params.c\"
  1114. else
  1115. echo shar: Extracting \"params.c\" \(3012 characters\)
  1116. sed "s/^X//" >params.c <<'END_OF_params.c'
  1117. X/*++
  1118. X/* NAME
  1119. X/*    params 3
  1120. X/* SUMMARY
  1121. X/*    communication parameter access
  1122. X/* PROJECT
  1123. X/*    pc-mail
  1124. X/* PACKAGE
  1125. X/*    library
  1126. X/* SYNOPSIS
  1127. X/*    #include "params.h"
  1128. X/*
  1129. X/*    Info *getparams();
  1130. X/* DESCRIPTION
  1131. X/*    getparams() returns a pointer to a table with communications
  1132. X/*    parameters. Usually communications parameters are set with the
  1133. X/*    "setup" option in the main menu of the interactive mail program.
  1134. X/*
  1135. X/*    First getparams() attempts to read from the setup file.
  1136. X/*    If that fails it creates an empty parameter table with
  1137. X/*    null string pointers as parameter values.
  1138. X/* FUNCTIONS AND MACROS
  1139. X/*    myalloc()
  1140. X/* BUGS
  1141. X/*    getparams() silently ignores any information in the
  1142. X/*    parameter file that it does not recognize.
  1143. X/*    getparams() will read the parameter file upon each call, even
  1144. X/*    if nothing has changed since the last read. Let us say that
  1145. X/*    it anticipates on multi-user environments.
  1146. X/* AUTHOR(S)
  1147. X/*    W.Z. Venema
  1148. X/*    Eindhoven University of Technology
  1149. X/*    Department of Mathematics and Computer Science
  1150. X/*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  1151. X/* CREATION DATE
  1152. X/*    Wed Apr  8 15:39:23 GMT+1:00 1987
  1153. X/* LAST MODIFICATION
  1154. X/*    Mon Apr  4 23:46:51 MET 1988
  1155. X/* VERSION/RELEASE
  1156. X/*    1.3
  1157. X/*--*/
  1158. X
  1159. X#include <ctype.h>
  1160. X#include "defs.h"
  1161. X#include "path.h"
  1162. X#include "params.h"
  1163. X
  1164. X/* Storage area for setup parameters */
  1165. X
  1166. Xhidden Info params[] = {
  1167. X    /* name */    /* name length */    /* string value */
  1168. X    PORT,    sizeof(PORT)-1,        0,
  1169. X    BAUD,    sizeof(BAUD)-1,        0,
  1170. X    HOST,    sizeof(HOST)-1,        0,
  1171. X    LOGIN,    sizeof(LOGIN)-1,    0,
  1172. X    DIAL,    sizeof(DIAL)-1,        0,
  1173. X    DISC,    sizeof(DISC)-1,        0,
  1174. X    0,        0,            0,
  1175. X};
  1176. X
  1177. Xhidden char *hackstr();                /* forward declaration */
  1178. X
  1179. X/* getparams - try to get info from file, else make empty table */
  1180. X
  1181. Xpublic Info *getparams()
  1182. X{
  1183. X    char line[BUFSIZ];
  1184. X    register Info *ip;
  1185. X    FILE *fp;
  1186. X
  1187. X    /* for cleanliness, we first clear all table entries */
  1188. X
  1189. X    for (ip = params; ip->ident; ip++) {
  1190. X    if (ip->strval)
  1191. X        free(ip->strval);
  1192. X    ip->strval = NULL;
  1193. X    }
  1194. X
  1195. X    /* then, try to copy parameter file info to the table */
  1196. X
  1197. X    if (fp = fopen(parm_file(),"r")) {
  1198. X    while (fgets(line,BUFSIZ,fp)) {
  1199. X        for(ip = params; ip->ident; ip++) {
  1200. X        if (strncmp(ip->ident,line,ip->length) == 0) {
  1201. X            ip->strval = hackstr(line+ip->length);
  1202. X            break;
  1203. X        }
  1204. X        }
  1205. X    }
  1206. X    fclose(fp);
  1207. X    }
  1208. X    return(params);
  1209. X}
  1210. X
  1211. X/* hackstr - cut away blanks around string and make copy */
  1212. X
  1213. Xhidden char *hackstr(s)
  1214. Xregister char *s;
  1215. X{
  1216. X    register char *r;
  1217. X    int len;
  1218. X
  1219. X    while (*s && isspace(*s))                /* trim leading blks */
  1220. X    s++;
  1221. X    for (r = s+strlen(s); r > s && isspace(r[-1]); r--)    /* trim trailing blks */
  1222. X    /* void */ ;
  1223. X
  1224. X    /*
  1225. X    * s is at the terminator or first non-blank char.
  1226. X    * r is at the terminator or first blank after the last non-blank char.
  1227. X    * Thus, the actual string length is r-s. We add one for the terminator.
  1228. X    * We don't allocate memory if the string is empty.
  1229. X    */
  1230. X
  1231. X    if (len = r-s) {
  1232. X    char *cp = strncpy(myalloc(len+1),s,len);
  1233. X    cp[len] = '\0';
  1234. X    return(cp);
  1235. X    } else {
  1236. X    return(NULL);
  1237. X    }
  1238. X}
  1239. END_OF_params.c
  1240. if test 3012 -ne `wc -c <params.c`; then
  1241.     echo shar: \"params.c\" unpacked with wrong size!
  1242. fi
  1243. # end of overwriting check
  1244. fi
  1245. if test -f path.c -a "${1}" != "-c" ; then 
  1246.   echo shar: Will not over-write existing file \"path.c\"
  1247. else
  1248. echo shar: Extracting \"path.c\" \(3402 characters\)
  1249. sed "s/^X//" >path.c <<'END_OF_path.c'
  1250. X/*++
  1251. X/* NAME
  1252. X/*      path 3
  1253. X/* SUMMARY
  1254. X/*      system-dependent file name stuff
  1255. X/* PROJECT
  1256. X/*      pc-mail
  1257. X/* PACKAGE
  1258. X/*      general
  1259. X/* SYNOPSIS
  1260. X/*    #include "str.h"
  1261. X/*      #include "path.h"
  1262. X/*
  1263. X/*      int pathinit()
  1264. X/*
  1265. X/*      FILE *propen()
  1266. X/*
  1267. X/*      char *fspool(file)
  1268. X/*      char *file;
  1269. X/* DESCRIPTION
  1270. X/*      The routines in this module know the system-dependent rules
  1271. X/*      for file names and printers.
  1272. X/*
  1273. X/*      pathinit() extracts the values of the environment variables
  1274. X/*      MAILDIR, MAILPRN, MAILCMD and EDITOR, and assumes system-dependent 
  1275. X/*    defaults for undefined environment variables. It checks for the 
  1276. X/*      existence of the spool directory.
  1277. X/*
  1278. X/*    Under Unix, the MAILPRN environment variable should be the name
  1279. X/*    of a command. Under MS-DOS, it should be the name of a device or file.
  1280. X/*
  1281. X/*      propen() returns stream to print to.
  1282. X/*
  1283. X/*      fspool() constructs a path name from the spool directory and 
  1284. X/*    the file name in its argument.
  1285. X/*    Real unix uses uucp spool file names of the form 
  1286. X/*
  1287. X/*        <letter> . <system> <grade> <sequencenr>
  1288. X/*
  1289. X/*    This is problematic for MS-DOS and similar systems that
  1290. X/*    only allow three characters after the dot. Instead of building
  1291. X/*    a tiny file system on top of MS-DOS, the pc-mail programs
  1292. X/*    use a different way of spool file naming:
  1293. X/*
  1294. X/*        <letter> <sequencenr>
  1295. X/*
  1296. X/*    This scheme assumes that the pc has access to exactly one unix
  1297. X/*    host, since the host name is not part of spool file names.
  1298. X/* COMMANDS
  1299. X/*      lp(1)  (under unix) printer spooler program
  1300. X/* FILES
  1301. X/*      PRN     under MS-DOS
  1302. X/* DIAGNOSTICS
  1303. X/*      pathinit() returns a nonzero value (see status(5)) if one of the 
  1304. X/*    environment variables (or defaults) are incorrect.
  1305. X/*
  1306. X/*      File open functions return a null pointer when a file could not
  1307. X/*      be opened.
  1308. X/* BUGS
  1309. X/*    pathinit() only verifies the MAILDIR name.
  1310. X/*
  1311. X/*      fspool() returns a pointer to static memory.
  1312. X/* AUTHOR(S)
  1313. X/*      W.Z. Venema
  1314. X/*      Eindhoven University of Technology
  1315. X/*      Department of Mathematics and Computer Science
  1316. X/*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  1317. X/* CREATION DATE
  1318. X/*      Sun Apr  5 15:27:37 GMT+1:00 1987
  1319. X/* LAST MODIFICATION
  1320. X/*    Wed Apr  6 00:21:17 MET 1988
  1321. X/* VERSION/RELEASE
  1322. X/*    1.4
  1323. X/*--*/
  1324. X
  1325. X#include <sys/types.h>
  1326. X#include <sys/stat.h>
  1327. X#include "defs.h"
  1328. X#include "path.h"
  1329. X#include "status.h"
  1330. X
  1331. X/*
  1332. X* Environment variables are loaded here. Most of them have a default;
  1333. X* We only check the validity of the MAILDIR variable.
  1334. X*/
  1335. X
  1336. Xpublic char *maildir = DEFSPOOL;        /* spool directory */
  1337. Xpublic char *editor  = DEFEDIT;            /* editor program */
  1338. Xpublic char *mailprn = DEFPRINT;        /* where to print to */
  1339. Xpublic char *mailcmd = 0;            /* do this on exit */
  1340. X
  1341. Xtypedef struct {
  1342. X    char *vname;
  1343. X    char **ptr;
  1344. X} Environ;
  1345. X
  1346. Xstatic Environ env[] = {
  1347. X    "SPOOL",    &maildir,            /* backwards compatibility... */
  1348. X    "MAILDIR",    &maildir,
  1349. X    "EDITOR",    &editor,
  1350. X    "MAILPRN",    &mailprn,
  1351. X    "MAILCMD",    &mailcmd,
  1352. X    0,        0,
  1353. X};
  1354. X
  1355. X/* pathinit - consult the environment; checks existence of spool directory */
  1356. X
  1357. Xpublic int pathinit()
  1358. X{
  1359. X    register char *cp;
  1360. X    struct stat s;
  1361. X    register Environ *ep;
  1362. X
  1363. X    /* load environment variables */
  1364. X
  1365. X    for (ep = env; ep->vname; ep++)
  1366. X    if (cp = getenv(ep->vname))
  1367. X        *(ep->ptr) = cp;
  1368. X
  1369. X    /* check existence of the spool directory */
  1370. X
  1371. X    return(stat(maildir,&s) || (s.st_mode&S_IFMT) != S_IFDIR ? E_NOSPOOL : 0);
  1372. X}
  1373. END_OF_path.c
  1374. if test 3402 -ne `wc -c <path.c`; then
  1375.     echo shar: \"path.c\" unpacked with wrong size!
  1376. fi
  1377. # end of overwriting check
  1378. fi
  1379. if test -f screen.h -a "${1}" != "-c" ; then 
  1380.   echo shar: Will not over-write existing file \"screen.h\"
  1381. else
  1382. echo shar: Extracting \"screen.h\" \(4000 characters\)
  1383. sed "s/^X//" >screen.h <<'END_OF_screen.h'
  1384. X/*++
  1385. X/* NAME
  1386. X/*    screen
  1387. X/* SUMMARY
  1388. X/*    structure of mail shell command windows
  1389. X/* PROJECT
  1390. X/*    pc-mail
  1391. X/* PACKAGE
  1392. X/*    mailsh
  1393. X/* SYNOPSIS
  1394. X/*    #include "screen.h"
  1395. X/* DESCRIPTION
  1396. X/*    The data structures in this file are used by the interactive shell to 
  1397. X/*    define what a screen looks like, and what commands the user can give.
  1398. X/*
  1399. X/*    For each screen, one has to define a table of (selector, command name, 
  1400. X/*    help string, and function pointer) tuples.
  1401. X/*    The command names are listed in the top window. If the user enters
  1402. X/*    the type of input specified by the selector, the associated function
  1403. X/*    is called. A null function pointer means go back to the calling screen. 
  1404. X/*
  1405. X/*    The table is terminated with a null selector entry; its help 
  1406. X/*    string is displayed in the bottom window (as a prompt), and the 
  1407. X/*    associated function is invoked upon entry of the screen.
  1408. X/*
  1409. X/*    The return value of an action function determines what happens next.
  1410. X/*    An action function can signal an error condition, that the screen
  1411. X/*    needs to be redrawn, and whether the calling screen should terminate.
  1412. X/*
  1413. X/*    User input can be of various forms: single-character, string or
  1414. X/*    escape/enter.
  1415. X/*
  1416. X/*    In case of single-character input the selector fields should contain 
  1417. X/*    for each key the (upper case) key code,
  1418. X/*    a label that is displayed at the top of the screen, and a help
  1419. X/*    text that explains the key's function. 
  1420. X/*
  1421. X/*    In case of string input the associated function is called with the 
  1422. X/*    string input as argument. If that function returns an error status the
  1423. X/*    text in the help field is printed in the error window and the 
  1424. X/*    user is given another chance.
  1425. X/*
  1426. X/*    In case of escape/enter the interpreter invokes the action function when
  1427. X/*    the user presses enter, and does nothing when escape is pressed. 
  1428. X/* .nf
  1429. X
  1430. X/* /* there is a Screen structure for each command for each screen */
  1431. X
  1432. Xtypedef struct {
  1433. X    short key;            /* type of input */
  1434. X    char *name;            /* key label (for top window) */
  1435. X    int  (*action)();        /* action when command is selected */
  1436. X    char *help;            /* explanation (for H command) */
  1437. X} Screen;
  1438. X
  1439. X/* /* action function return masks */
  1440. X
  1441. X#define    S_BREAK        1    /* return immediately after action */
  1442. X#define    S_REDRAW    2    /* redraw screen */
  1443. X#define    S_ERROR        4    /* action failed */
  1444. X
  1445. X/* /* input types: ordinary character keys are encoded as themselves */
  1446. X
  1447. X#define    BS    '\010'
  1448. X#define    ENTER    '\015'
  1449. X#define    ESC    '\033'
  1450. X#define    DEL    '\177'
  1451. X
  1452. X#define    ANY    256        /* press any key */
  1453. X#define    UP    257        /* up-arrow key */
  1454. X#define    DOWN    258        /* down-arrow key */
  1455. X#define    LEFT    259        /* left-arrow key */
  1456. X#define    RIGHT    260        /* right-arrow key */
  1457. X#define    PGUP    261        /* page-up */
  1458. X#define    PGDN    262        /* page-down */
  1459. X#define    STRING    263        /* string input, ESC to quit */
  1460. X#define    ESCCR    264        /* CR to confirm, ESC to quit */
  1461. X
  1462. X#define    iskey(key)    (key > 0 && key < STRING)
  1463. X
  1464. X/* /* system-dependent function-key labels */
  1465. X
  1466. X#ifdef unix
  1467. X#   define PgUp    "F1"
  1468. X#   define PgDn "F2"
  1469. X#endif
  1470. X
  1471. X#ifdef MSDOS
  1472. X#   define PgUp "PgUp"
  1473. X#   define PgDn "PgDn"
  1474. X#endif
  1475. X
  1476. X/* /* often-used strings and messages */
  1477. X
  1478. Xextern char initscreen[];    /* Return to initial screen */
  1479. Xextern char int_error[];    /* The program is confused */
  1480. Xextern char pageup[];        /* Move screen one page upwards */
  1481. Xextern char pagedn[];        /* Move screen one page downwards */
  1482. Xextern char csrup[];        /* Move cursor upwards */
  1483. Xextern char csrdn[];        /* Move cursor downwards */
  1484. Xextern char getsummary[];    /* Press ESC to cancel.. */
  1485. Xextern char printcurr[];    /* Print current message */
  1486. Xextern char delcurr[];        /* Delete current message */
  1487. Xextern char *m_msgread[];    /* Cannot read that message */
  1488. X/* SEE ALSO
  1489. X/*    screen(3)    screen table implementation
  1490. X/*    kbdinp(3)    screen table interpreter
  1491. X/* AUTHOR(S)
  1492. X/*    W.Z. Venema
  1493. X/*    Eindhoven University of Technology
  1494. X/*    Department of Mathematics and Computer Science
  1495. X/*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  1496. X/* CREATION DATE
  1497. X/*    Wed Apr  1 21:14:53 GMT+1:00 1987
  1498. X/* LAST MODIFICATION
  1499. X/*    Mon Apr  4 23:49:07 MET 1988
  1500. X/* VERSION/RELEASE
  1501. X/*    1.3
  1502. X/*--*/
  1503. END_OF_screen.h
  1504. if test 4000 -ne `wc -c <screen.h`; then
  1505.     echo shar: \"screen.h\" unpacked with wrong size!
  1506. fi
  1507. # end of overwriting check
  1508. fi
  1509. if test -f setup.c -a "${1}" != "-c" ; then 
  1510.   echo shar: Will not over-write existing file \"setup.c\"
  1511. else
  1512. echo shar: Extracting \"setup.c\" \(4003 characters\)
  1513. sed "s/^X//" >setup.c <<'END_OF_setup.c'
  1514. X/*++
  1515. X/* NAME
  1516. X/*    setup 3
  1517. X/* SUMMARY
  1518. X/*    edit/display configuration parameters
  1519. X/* PROJECT
  1520. X/*    pc-mail
  1521. X/* PACKAGE
  1522. X/*    mailsh
  1523. X/* SYNOPSIS
  1524. X/*    #include "mailsh.h"
  1525. X/*
  1526. X/*    int setup()
  1527. X/* DESCRIPTION
  1528. X/*    The functions in this module handle the configurations file with 
  1529. X/*    communications parameters.
  1530. X/*
  1531. X/*    setup() starts a dialogue with the user. It allows the user to
  1532. X/*    select a parameter and enter a new value. All modifications are
  1533. X/*    done in core (pager file). Upon exit, the setup is written to 
  1534. X/*    disk if any changes were made.
  1535. X/* FUNCTIONS AND MACROS
  1536. X/*    open_pager(), app_pager(), gets_pager(), puts_pager()
  1537. X/*    kbdinp()
  1538. X/* FILES
  1539. X/*    In the spool directory: the configuration file s00000.
  1540. X/* SEE ALSO
  1541. X/*    cico(1)    communications program.
  1542. X/* DIAGNOSTICS
  1543. X/*    An error message if the setup file could not be created.
  1544. X/* BUGS
  1545. X/*    Does not check parameter values at all, just like the UUCP 
  1546. X/*    configurations files L.sys etcetera.
  1547. X/* AUTHOR(S)
  1548. X/*    W.Z. Venema
  1549. X/*    Eindhoven University of Technology
  1550. X/*    Department of Mathematics and Computer Science
  1551. X/*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  1552. X/* CREATION DATE
  1553. X/*    Wed Apr  8 15:16:18 GMT+1:00 1987
  1554. X/* LAST MODIFICATION
  1555. X/*    Mon Apr  4 23:49:37 MET 1988
  1556. X/* VERSION/RELEASE
  1557. X/*    1.3
  1558. X/*--*/
  1559. X
  1560. X#include "defs.h"
  1561. X#include "path.h"
  1562. X#include "screen.h"
  1563. X#include "mailsh.h"
  1564. X#include "pager.h"
  1565. X#include "params.h"
  1566. X#include "status.h"
  1567. X#include "window.h"
  1568. X
  1569. Xhidden void make_setup();            /* forward declarations */
  1570. Xhidden int change_setup();
  1571. Xhidden int pick_setup();
  1572. Xhidden int show_setup();
  1573. X
  1574. Xhidden File *setfile = 0;            /* memory! */
  1575. Xhidden Info *prmtable = 0;            /* more memory */
  1576. Xhidden int chgflag = 0;                /* more flags! */
  1577. X
  1578. X/* setup - start dialogue */
  1579. X
  1580. Xpublic int setup()
  1581. X{
  1582. X    static Screen screen[] = {
  1583. X    'C',    "Close",        0,      initscreen,
  1584. X    PGUP,    PgUp,        pu_pager,pageup,
  1585. X    PGDN,    PgDn,        pd_pager,pagedn,
  1586. X    UP,    "Up",           up_pager,csrup,
  1587. X    DOWN,    "Down",         dn_pager,csrdn,
  1588. X    ENTER,    "Enter",        pick_setup,"Modify selected parameter",
  1589. X    0,    0,              show_setup,
  1590. X    "Select communications parameter with cursor keys, then press ENTER",
  1591. X    };
  1592. X
  1593. X    kbdinp(screen);                /* start dialogue */
  1594. X    if (chgflag && cp_pager(parm_file())) {
  1595. X    errdisp(E_WRITERR);            /* save failed */
  1596. X    } else {
  1597. X    chgflag = 0;                /* save succeeded */
  1598. X    }
  1599. X    close_pager(setfile);
  1600. X    setfile = 0;
  1601. X    return(S_REDRAW);                /* refresh screen */
  1602. X}
  1603. X
  1604. X/* show_setup - make setup display or use existing one */
  1605. X
  1606. Xhidden int show_setup()
  1607. X{
  1608. X    if (setfile == 0 || prmtable == 0) {    /* no setup display */
  1609. X    prmtable = getparams();
  1610. X    setfile = open_pager();
  1611. X    make_setup();
  1612. X    } else {                    /* use existing display */
  1613. X    set_pager(setfile);
  1614. X    }
  1615. X    ds_pager();                    /* display it */
  1616. X    return(0);
  1617. X}
  1618. X
  1619. X/* make_setup - create setup display */
  1620. X
  1621. Xhidden void make_setup()
  1622. X{
  1623. X    register File *f = setfile;
  1624. X    register Info *i;
  1625. X
  1626. X    for (i = prmtable; i->ident; i++)
  1627. X    app_pager(f,strcons("%-20s %s",i->ident,i->strval ? i->strval : ""));
  1628. X}
  1629. X
  1630. X/* pick_setup - user has selected one parameter */
  1631. X
  1632. Xhidden int pick_setup()
  1633. X{
  1634. X    static Screen screen[] = {
  1635. X    STRING,    0,              change_setup,int_error,
  1636. X    0,    0,              0,
  1637. X    "Press ESC to cancel. New parameter value:"
  1638. X    };
  1639. X    register char *sp = gets_pager();
  1640. X    register Info *ip;
  1641. X
  1642. X    for (ip = prmtable; ip->ident; ip++)        /* check id string */
  1643. X    if (strncmp(ip->ident,sp,ip->length) == 0)
  1644. X        break;
  1645. X    if (ip) {
  1646. X    kbdinp(screen);                    /* ask for new value */
  1647. X    return(S_REDRAW);
  1648. X    } else {
  1649. X    beep();                        /* bad id string */
  1650. X    return(0);
  1651. X    }
  1652. X}
  1653. X
  1654. X/* change_setup - enter new communications parameter value */
  1655. X
  1656. Xhidden int change_setup(newval)
  1657. Xchar *newval;
  1658. X{
  1659. X    register char *sp = gets_pager();            /* read from display */
  1660. X    register Info *ip;
  1661. X
  1662. X    for (ip = prmtable; ip->ident; ip++) {        /* check id string */
  1663. X    if (strncmp(ip->ident,sp,ip->length) == 0) {
  1664. X        puts_pager(strcons("%-20s %s",ip->ident,newval)); /* new entry */
  1665. X        chgflag = 1;                /* say change made */
  1666. X    }
  1667. X    }
  1668. X    return(S_BREAK|S_REDRAW);                /* screen changed */
  1669. X}
  1670. END_OF_setup.c
  1671. if test 4003 -ne `wc -c <setup.c`; then
  1672.     echo shar: \"setup.c\" unpacked with wrong size!
  1673. fi
  1674. # end of overwriting check
  1675. fi
  1676. if test -f str.c -a "${1}" != "-c" ; then 
  1677.   echo shar: Will not over-write existing file \"str.c\"
  1678. else
  1679. echo shar: Extracting \"str.c\" \(3979 characters\)
  1680. sed "s/^X//" >str.c <<'END_OF_str.c'
  1681. X/*++
  1682. X/* NAME
  1683. X/*    strcons,istrcmp,strvec,vecstr 3
  1684. X/* SUMMARY
  1685. X/*    string utility routines
  1686. X/* PROJECT
  1687. X/*    pc-mail
  1688. X/* PACKAGE
  1689. X/*    general stuff
  1690. X/* SYNOPSIS
  1691. X/*    char *strcons(format,args)
  1692. X/*    char *format;
  1693. X/*
  1694. X/*    int istrcmp(s1,s2)
  1695. X/*    char *s1,s2;
  1696. X/*
  1697. X/*    char **strvec(string,separ)
  1698. X/*    char *string;
  1699. X/*    char *separ;
  1700. X/*
  1701. X/*    char *vecstr(vector,separ)
  1702. X/*    char **vector;
  1703. X/*    char *separ;
  1704. X/* DESCRIPTION
  1705. X/*    strcons() produces a formatted string, using printf()-like
  1706. X/*    arguments. Basically it is an sprintf() that returns a 
  1707. X/*    pointer to the result.
  1708. X/*
  1709. X/*    istrcmp() is a case-insensitive versions of the strcmp() functions.
  1710. X/*
  1711. X/*    strvec() breaks a null-terminated string using the separators given 
  1712. X/*    in separ, and returns a null-terminated vector of pointers to the 
  1713. X/*    resulting substrings. Memory for the vector and substrings are 
  1714. X/*    allocated in dynamic memory. The original string is not modified.
  1715. X/*
  1716. X/*    vecstr() takes a null-terminated vector of string pointers
  1717. X/*    and builds a string from the strings pointed to by the vector
  1718. X/*    argument, separated by the string in the separ argument.
  1719. X/*    Memory for the result is allocated in dynamic memory.
  1720. X/* FUNCTIONS AND MACROS
  1721. X/*    strtok(), malloc(), memcpy(), sprintf()
  1722. X/* DIAGNOSTICS
  1723. X/*    strvec(), vecstr() return a null pointer if there was not enough memory
  1724. X/*    avaliable to hold the result.
  1725. X/* BUGS
  1726. X/*    strcons() does not do smart garbage collection; it just uses
  1727. X/*    a circular buffer. The present implementation is not portable 
  1728. X/*    to machines that pass arguments via registers.
  1729. X/*
  1730. X/*    strvec() cannot handle strings with more than BUFSIZ words.
  1731. X/*    strvec() uses strtok(), which may have side effects.
  1732. X/* AUTHOR(S)
  1733. X/*    W.Z. Venema
  1734. X/*    Eindhoven University of Technology
  1735. X/*    Department of Mathematics and Computer Science
  1736. X/*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  1737. X/* CREATION DATE
  1738. X/*    Tue Apr  5 20:59:29 MET 1988
  1739. X/* LAST MODIFICATION
  1740. X/*    Wed Apr  6 00:23:08 MET 1988
  1741. X/* VERSION/RELEASE
  1742. X/*    1.1
  1743. X/*--*/
  1744. X
  1745. X#include <ctype.h>
  1746. X
  1747. X#include "defs.h"
  1748. X
  1749. X#define    NBUF    4
  1750. X
  1751. X/* strcons - quick-and-dirty string constructor */
  1752. X
  1753. X/* VARARGS1 */
  1754. X
  1755. Xchar *strcons(fmt,a1,a2,a3,a4)
  1756. Xchar *fmt;
  1757. Xlong a1,a2,a3,a4;
  1758. X{
  1759. X    static char strbuf[NBUF][BUFSIZ];
  1760. X    static int where = 0;
  1761. X    register char *cp;
  1762. X
  1763. X    sprintf(cp = strbuf[where = (where+1)%NBUF],fmt,a1,a2,a3,a4);
  1764. X    return(cp);
  1765. X}
  1766. X
  1767. X/* istrcmp - case-insensitive string comparison */
  1768. X
  1769. X#define    LOW(c)    (isascii(c)&&isupper(c)?tolower(c):(c))
  1770. X
  1771. Xint istrcmp(s1,s2)
  1772. Xregister char *s1,*s2;
  1773. X{
  1774. X    while (*s1 && (LOW(*s1) == LOW(*s2)))
  1775. X    s1++,s2++;
  1776. X    return(LOW(*s1)-LOW(*s2));
  1777. X}
  1778. X
  1779. X/* strvec - make vector of substring pointers */
  1780. X
  1781. Xchar **strvec(str,sep)
  1782. Xchar *str;
  1783. Xchar *sep;
  1784. X{
  1785. X    char *tmp[BUFSIZ];            /* scratch substring pointer storage */
  1786. X    register char **cpp = tmp;
  1787. X    char *sp;                /* ptr to private copy of original */
  1788. X    register int bytec;
  1789. X
  1790. X    /* make a copy of the original string */
  1791. X
  1792. X    if ((sp = malloc(strlen(str)+1)) == 0)
  1793. X    return(0);
  1794. X    strcpy(sp,str);
  1795. X
  1796. X    /* chop our copy at sequences of one or more separators */
  1797. X
  1798. X    for (*cpp = strtok(sp,sep); *cpp; *++cpp = strtok((char *)0,sep))
  1799. X    /* void */ ;
  1800. X
  1801. X    /* now construct the vector of pointers to the substrings */
  1802. X
  1803. X    if ((cpp = (char **) malloc(bytec = (cpp-tmp+1)*sizeof(*cpp))) == 0)
  1804. X    return(0);
  1805. X    return((char **)memcpy((char *)cpp,(char *)tmp,bytec));
  1806. X}
  1807. X
  1808. X/* vecstr - null-terminated vector of string pointers to one flat string */
  1809. X
  1810. Xpublic char *vecstr(vec,sep)
  1811. Xchar **vec;
  1812. Xchar *sep;
  1813. X{
  1814. X    register char **cpp;
  1815. X    register int len = 0;        /* length of final string */
  1816. X    register char *cp;
  1817. X    register int flen = strlen(sep);    /* filler between substrings */
  1818. X
  1819. X    /* find out how big the resulting string will be */
  1820. X
  1821. X    for (cpp = vec; *cpp; cpp++)
  1822. X    len += strlen(*cpp)+flen;
  1823. X
  1824. X    /* allocate and initialize the result string */
  1825. X
  1826. X    if ((cp = malloc(len+1)) == 0)
  1827. X    return(0);
  1828. X    *cp = '\0';
  1829. X
  1830. X    /* fill the resulting string */
  1831. X
  1832. X    for (cpp = vec; *cpp; cpp++) {
  1833. X    strcat(cp,*cpp);
  1834. X    strcat(cp,sep);
  1835. X    }
  1836. X    return(cp);
  1837. X}
  1838. END_OF_str.c
  1839. if test 3979 -ne `wc -c <str.c`; then
  1840.     echo shar: \"str.c\" unpacked with wrong size!
  1841. fi
  1842. # end of overwriting check
  1843. fi
  1844. if test -f termcap/README -a "${1}" != "-c" ; then 
  1845.   echo shar: Will not over-write existing file \"termcap/README\"
  1846. else
  1847. echo shar: Extracting \"termcap/README\" \(393 characters\)
  1848. sed "s/^X//" >termcap/README <<'END_OF_termcap/README'
  1849. XMS-DOS Implementation notes, W.Z. Venema, Eindhoven University of Technology
  1850. X
  1851. XThe functions presented here implement UNIX-style terminal-independent
  1852. Xoperation routines for cursor addressing, video attributes etc.
  1853. X
  1854. XThe functions are effective for the ibm pc console, and assume that the 
  1855. XMS-DOS driver ANSI.SYS is loaded. The capabilities for the console are
  1856. Xstored in a static data structure.
  1857. END_OF_termcap/README
  1858. if test 393 -ne `wc -c <termcap/README`; then
  1859.     echo shar: \"termcap/README\" unpacked with wrong size!
  1860. fi
  1861. # end of overwriting check
  1862. fi
  1863. if test -f termcap/console.c -a "${1}" != "-c" ; then 
  1864.   echo shar: Will not over-write existing file \"termcap/console.c\"
  1865. else
  1866. echo shar: Extracting \"termcap/console.c\" \(2788 characters\)
  1867. sed "s/^X//" >termcap/console.c <<'END_OF_termcap/console.c'
  1868. X/*++
  1869. X/* NAME
  1870. X/*      console 3
  1871. X/* SUMMARY
  1872. X/*      encoded ibm pc console terminal capabilities
  1873. X/* PROJECT
  1874. X/*       ms-dos/unix compatibility
  1875. X/* PACKAGE
  1876. X/*      termcap
  1877. X/* SYNOPSIS
  1878. X/*      #include "termcap.h"
  1879. X/* DESCRIPTION
  1880. X/*      The terminal capabilities for the ibm pc ANSI.SYS console driver
  1881. X/*      are stored in a static data structure named "_console". 
  1882. X/*      User access proceeds through the tget{num|str|flag} functions.
  1883. X/*
  1884. X/*      The escape character at the start of function key codes are
  1885. X/*      imaginary; the PC hardware actually returns a nul byte.
  1886. X/* SEE ALSO
  1887. X/*      tgetnum(3), tgetstr(3), tgetflag(3).
  1888. X/*      termcap(3), Berkeley extensions to UNIX.
  1889. X/* FILES
  1890. X/*      ANSI.SYS, ibm pc console driver.
  1891. X/* AUTHOR(S)
  1892. X/*      W.Z. Venema
  1893. X/*      Eindhoven University of Technology
  1894. X/*      Department of Mathematics and Computer Science
  1895. X/*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  1896. X/* CREATION DATE
  1897. X/*      Wed Jan  1 19:01:13 GMT+1:00 1986
  1898. X/* LAST MODIFICATION
  1899. X/*      Wed Jan  1 19:01:13 GMT+1:00 1986
  1900. X/* VERSION/RELEASE
  1901. X/*      1.0
  1902. X/*--*/
  1903. X
  1904. X#include "termcap.h"
  1905. X
  1906. XCap _console[] = {
  1907. X        "am",   0,                      /* auto CR-LF at right margin */
  1908. X        "bs",   0,                      /* terminal can backspace */
  1909. X        "cd",   "\033[J",               /* clear to end of screen */
  1910. X        "ce",   "\033[K",               /* clear to end of line */
  1911. X        "cl",   "\033[;H\033[2J",       /* clear whole screen */
  1912. X        "cm",   "\033[%i%d;%dH",        /* cursor movement */
  1913. X        "co",   "80",                   /* nbr of columns on screen */
  1914. X        "cr",   "\r",                   /* carriage-return */
  1915. X        "do",   "\033[B",               /* cursor down */
  1916. X        "ku",   "\033H",                /* up-arrow key */
  1917. X        "kd",   "\033P",                /* down-arrow key */
  1918. X        "kl",   "\033L",                /* left-arrow key */
  1919. X        "kr",   "\033N",                /* right-arrow key */
  1920. X        "le",   "\010",                 /* cursor left */
  1921. X        "li",   "25",                   /* nbr of lines on screen */
  1922. X        "nd",   "\033[C",               /* cursor right */
  1923. X        "nl",   "\n",                   /* linefeed character */
  1924. X        "pt",   "",                     /* has hardware tabs */
  1925. X        "PU",   "\033I",                /* page up key */
  1926. X        "PD",   "\033Q",                /* page down key */
  1927. X        "se",   "\033[m",               /* end standout mode */
  1928. X        "so",   "\033[1m",              /* enter standout (bold) mode */
  1929. X        "ue",   "\033[m",               /* end underscore mode */
  1930. X        "up",   "\033[A",               /* cursor up */
  1931. X        "us",   "\033[4m",              /* enter underscore mode */
  1932. X        0,      0,                      /* terminator */
  1933. X};
  1934. X
  1935. END_OF_termcap/console.c
  1936. if test 2788 -ne `wc -c <termcap/console.c`; then
  1937.     echo shar: \"termcap/console.c\" unpacked with wrong size!
  1938. fi
  1939. # end of overwriting check
  1940. fi
  1941. echo shar: End of archive 6 \(of 8\).
  1942. cp /dev/null ark6isdone
  1943. MISSING=""
  1944. for I in 1 2 3 4 5 6 7 8 ; do
  1945.     if test ! -f ark${I}isdone ; then
  1946.     MISSING="${MISSING} ${I}"
  1947.     fi
  1948. done
  1949. if test "${MISSING}" = "" ; then
  1950.     echo You have unpacked all 8 archives.
  1951.     rm -f ark[1-9]isdone
  1952. else
  1953.     echo You still need to unpack the following archives:
  1954.     echo "        " ${MISSING}
  1955. fi
  1956. ##  End of shell archive.
  1957. exit 0
  1958. -- 
  1959. uucp:    mcvax!eutrc3!wswietse    | Eindhoven University of Technology
  1960. bitnet:    wswietse@heithe5    | Dept. of Mathematics and Computer Science
  1961. surf:    tuerc5::wswietse    | Eindhoven, The Netherlands.
  1962.